//package com.ekgc.addressbook.base.config;
//
//
//
//
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.NoArgsConstructor;
//
//import java.util.List;
//
//@Data
//@NoArgsConstructor
//@AllArgsConstructor
////public class Result {
//public class Result<T> {
//    private Boolean success;
//    private String errorMsg;
////    private Object data;
//    private int code;
//    private T data;
//    private Long total;
//
//    public static Result ok(){
//        return new Result(true, null, null, 200,null);
//    }
//    public static Result ok(Object data){
//        return new Result(true, null, data, 200,null);
//    }
////    public static Result ok(List<?> data, Long total){
////        return new Result(true, null, data, 200,total);
////    }
//
//    public static <T> Result<T> ok(T data, long total) {
//        return new Result<>(data, total);
//    }
//    public static Result fail(String errorMsg){
//        return new Result(false, errorMsg, null, 500,null);
//    }
//}


package com.ekgc.addressbook.base.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
// 修改点 1: 类添加泛型声明，支持不同类型的数据
public class Result<T> {
    private Boolean success;
    private String errorMsg;
    private int code;
    private T data;
    private Long total;

    // 修改点 2: 构造函数添加泛型类型参数
    public Result(Boolean success, String errorMsg, T data, int code, Long total) {
        this.success = success;
        this.errorMsg = errorMsg;
        this.data = data;
        this.code = code;
        this.total = total;
    }

    // 修改点 3: 静态方法添加泛型声明
    public static <T> Result<T> ok() {
        return new Result<>(true, null, null, 200, null);
    }

    // 修改点 4: 静态方法添加泛型声明
    public static <T> Result<T> ok(T data) {
        return new Result<>(true, null, data, 200, null);
    }

    // 修改点 5: 静态方法添加泛型声明，支持不同类型的数据和总数
    public static <T> Result<T> ok(T data, long total) {
        return new Result<>(true, null, data, 200, total);
    }

    // 修改点 6: 静态方法添加泛型声明
    public static <T> Result<T> fail(String errorMsg) {
        return new Result<>(false, errorMsg, null, 500, null);
    }
}
